package com.zhufei.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.zhufei.entity.BBSSection;
import com.zhufei.entity.Sponsor;

public class BBSSectionDao extends DBCon{
	private static String TABLE = "zhufei_bbs_section";
	private static String NAME = "name";
	private static String INDEX = "index_";
	
	/**
	 * 修改两个栏目的名字
	 * @param left_name  左栏目
	 * @param right_name  右栏目
	 * @return
	 */
	public static boolean updateBBSSection(String left_name, String right_name){
		boolean a1 = updateLeftBBSSection( left_name);
		boolean a2 = updateRightBBSSection( right_name);
		return a1&&a2;
	}
	
	/**
	 * 修改论坛在主页上显示的左栏目名字
	 * @param name   栏目名字
	 * @return
	 */
	public static boolean updateLeftBBSSection(String left_name){
		int index = 1;
		DBCon con = new DBCon();
		try {
			Statement statement = con.getStatement();
			String sql = "update "+TABLE+" set "+NAME+"='"+left_name+"' where "+INDEX+"="+index;
			statement.executeUpdate(sql);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			con.closeDB();
		}
		return false;
	}
	
	/**
	 * 修改论坛在主页上显示的右栏目名字
	 * @param name   栏目名字
	 * @return
	 */
	public static boolean updateRightBBSSection(String right_name){
		int index = 2;
		DBCon con = new DBCon();
		try {
			Statement statement = con.getStatement();
			String sql = "update "+TABLE+" set "+NAME+"='"+right_name+"' where "+INDEX+"="+index;
			statement.executeUpdate(sql);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			con.closeDB();
		}
		return false;
	}
	
	/**
	 * 返回左栏目名字
	 * @return
	 */
	public static String getLeftSectionName(){
		int index = 1;
		String name = null;
		DBCon con = new DBCon();
		try {
			Statement statement = con.getStatement();
			String sql = null;
			sql = "select * from "+ TABLE + " where "+ INDEX + "="+index;
			
			ResultSet rs = statement.executeQuery(sql);
			while(rs.next()){
				name = rs.getString(NAME);
			}
			rs.close();
			return name;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			con.closeDB();
		}
		return null;
	}
	
	/**
	 * 返回右栏目名字
	 * @return
	 */
	public static String getRighttSectionName(){
		int index = 2;
		String name = null;
		DBCon con = new DBCon();
		try {
			Statement statement = con.getStatement();
			String sql = null;
			sql = "select * from "+ TABLE + " where "+ INDEX + "="+index;
			
			ResultSet rs = statement.executeQuery(sql);
			while(rs.next()){
				name = rs.getString(NAME);
			}
			rs.close();
			return name;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			con.closeDB();
		}
		return null;
	}
}
